<MContainer Fluid>
    <MSelect @bind-Value="_selectedFruits"
             Items="_fruits"
             Label="Favorite Fruits"
             ItemValue="r=>r"
             ItemText="r=>r"
             Multiple>
        <PrependItemContent>
            <MListItem OnClick="Toggle">
                <MListItemAction>
                    <MIcon Color="@(_selectedFruits.Count > 0 ? "indigo darken-4" : "")">
                        @Icon
                    </MIcon>
                </MListItemAction>
                <MListItemContent>
                    <MListItemTitle>
                        Select All
                    </MListItemTitle>
                </MListItemContent>
            </MListItem>
            <MDivider Class="mt-2"></MDivider>
        </PrependItemContent>
        <AppendItemContent>
            <MDivider Class="mb-2"></MDivider>
            <MListItem Disabled>
                <MListItemAvatar Color="grey lighten-3">
                    <MIcon>
                        mdi-food-apple
                    </MIcon>
                </MListItemAvatar>
                @if (LikesAllFruit)
                {
                    <MListItemContent>
                        <MListItemTitle>
                            Holy smokes, someone call the fruit police!
                        </MListItemTitle>
                    </MListItemContent>
                }
                else if (LikesSomeFruit)
                {
                    <MListItemContent>
                        <MListItemTitle>
                            Fruit Count
                        </MListItemTitle>
                        <MListItemSubtitle>
                            {{ _selectedFruits.length }}
                        </MListItemSubtitle>
                    </MListItemContent>
                }
                else
                {
                    <MListItemContent v-else>
                        <MListItemTitle>
                            How could you not like fruit?
                        </MListItemTitle>
                        <MListItemSubtitle>
                            Go ahead, make a selection above!
                        </MListItemSubtitle>
                    </MListItemContent>
                }
            </MListItem>
        </AppendItemContent>
    </MSelect>
</MContainer>

@code {
    private List<string> _fruits = new List<string>

      {
    "Apples",
    "Apricots",
    "Avocado",
    "Bananas",
    "Blueberries",
    "Blackberries",
    "Boysenberries",
    "Bread fruit",
    "Cantaloupes (cantalope)",
    "Cherries",
    "Cranberries",
    "Cucumbers",
    "Currants",
    "Dates",
    "Eggplant",
    "Figs",
    "Grapes",
    "Grapefruit",
    "Guava",
    "Honeydew melons",
    "Huckleberries",
    "Kiwis",
    "Kumquat",
    "Lemons",
    "Limes",
    "Mangos",
    "Mulberries",
    "Muskmelon",
    "Nectarines",
    "Olives",
    "Oranges",
    "Papaya",
    "Peaches",
    "Pears",
    "Persimmon",
    "Pineapple",
    "Plums",
    "Pomegranate",
    "Raspberries",
    "Rose Apple",
    "Starfruit",
    "Strawberries",
    "Tangerines",
    "Tomatoes",
    "Watermelons",
    "Zucchini"
    };
    private List<string> _selectedFruits = new List<string>();

    public bool LikesAllFruit => _selectedFruits.Count == _fruits.Count;

    public bool LikesSomeFruit => _selectedFruits.Count > 0 && !LikesAllFruit;

    public string Icon
    {
        get
        {
            if (LikesAllFruit)
            {
                return "mdi-close-box";
            }

            if (LikesSomeFruit)
            {
                return "mdi-minus-box";
            }

            return "mdi-checkbox-blank-outline";
        }
    }

    public void Toggle()
    {
        if (LikesAllFruit)
        {
            _selectedFruits = new List<string>();
        }
        else
        {
            _selectedFruits = new List<string>();
            _selectedFruits.AddRange(_fruits);
        }
    }
  }